import { reqGetAddressInfo, reqGetUserOrderList } from '@/api'

export default {

  namespaced: true,

  state: {
    // 服务器响应回来的数据
    userAddressInfo: [],
    userOrderList: {}

  },

  actions: {
    async getUserAddress({ commit }) {
      const result = await reqGetAddressInfo()
      if (result.code === 200) {
        commit('GETUSERADDRESS', result.data)
      }
    },
    async getUserOrderList({ commit }) {
      const result = await reqGetUserOrderList()
      if (result.code === 200) {
        commit('GETUSERORDERLIST', result.data)
      }
    }
  },

  mutations: {

    GETUSERADDRESS(state, userAddressInfo) {
      state.userAddressInfo = userAddressInfo
    },
    GETUSERORDERLIST(state, userOrderList) {
      state.userOrderList = userOrderList
    }
  },

  getters: {
    detailArrayList(state) {
      return state.userOrderList.detailArrayList || []
    }
  }
}
